<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<%
	pageContext.setAttribute("APP_PATH", request.getContextPath());
%>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>信息录入</title>
    <link rel="stylesheet" href="${APP_PATH}/static/bootstrap-3.3.7/css/bootstrap.css"/>
    <link rel="stylesheet" href="${APP_PATH}/static/bootstrap-3.3.7/plugins/fromvalidation/dist/css/formValidation.css"/>
	<link rel="stylesheet" type="text/css" href="${APP_PATH}/static/bootstrap-3.3.7/plugins/fromvalidation/default.css">
	<link rel="stylesheet" type="text/css" href="${APP_PATH}/static/bootstrap-3.3.7/plugins/datetimepicker/bootstrap-datetimepicker.min.css">
	<!--[if IE]>
		<script src="http://libs.baidu.com/html5shiv/3.7/html5shiv.min.js"></script>
	<![endif]-->
</head>

<body>
	<div class="container">
	        <div class="row">
	            <div class="col-sm-8">
	                <div class="page-header">
	                    <h3>基本信息录入</h3>
	                </div>

	                <form id="defaultForm" method="post" class="form-horizontal" action="${APP_PATH}/case/input">
	                	<div class="form-group">
	                    	<label for="collectDate" class="col-sm-3 control-label">采集日期</label>
	                    	<div class="col-sm-5">
	               			    <div class="input-group date form_date" data-date-format="yyyy-mm-dd" data-link-field="collectDate" >
				                    <input class="form-control" type="text" name="collectDate" readonly>
									<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
				                </div>
			                </div>
	                    </div>
	                    
	                    <div class="form-group">
	                        <label class="col-sm-3 control-label">姓名</label>
	                        <div class="col-sm-5">
	                            <input type="text" class="form-control" name="customerName" />
	                        </div>
	                    </div>
						<div class="form-group">
	                        <label class="col-sm-3 control-label">性别</label>
	                        <div class="col-sm-5">
	                            <div class="radio">
	                                <label>
	                                    <input type="radio" name="gender" value="1" /> 男
	                                </label>
	                           
	                                <label>
	                                    <input type="radio" name="gender" value="2" /> 女
	                                </label>
	                            </div>
	                            
	                        </div>
	                    </div>
	                    <div class="form-group">
	                        <label class="col-sm-3 control-label">电话号码</label>
	                        <div class="col-sm-5">
	                            <input type="text" class="form-control" name="phone"/>
	                        </div>
	                    </div>
 						<div class="form-group">
	                                <label class="col-sm-3 control-label">治疗医院</label>
	                                <div class="col-sm-5">
	                                    <select class="form-control" id="hospital" name="hospital">
	                                    </select>
	                                </div>
	                     </div>
 						<div class="form-group">
		                        <label class="col-sm-3 control-label">案件类型</label>
		                        <div class="col-sm-5" id="accidentTypeDiv">
		                        </div>
		                    </div>
						<div class="form-group">
	                        <label class="col-sm-3 control-label">劳动合同</label>
	                        <div class="col-sm-6">
	                            <div class="radio">
	                                <label>
	                                    <input type="radio" name="hasContract" value="1" /> 有
	                                </label>
	                           
	                                <label>
	                                    <input type="radio" name="hasContract" value="0" /> 无
	                                </label>
	                            </div>
	                            
	                        </div>
	                    </div>
	                    <div class="form-group">
	                        <label class="col-sm-3 control-label">社保</label>
	                        <div class="col-sm-6">
	                            <div class="radio">
	                                <label>
	                                    <input type="radio" name="hasInsurance" value="1" /> 有
	                                </label>
	                           
	                                <label>
	                                    <input type="radio" name="hasInsurance" value="0" /> 无
	                                </label>
	                            </div>
	                            
	                        </div>
	                    </div>
					    <div class="form-group">
	                        <label class="col-sm-3 control-label">工资结算方式</label>
	                        <div class="col-sm-6">
	                            <div class="radio">
	                                <label>
	                                    <input type="radio" name="wageType" value="1" /> 打卡
	                                </label>
	                           
	                                <label>
	                                    <input type="radio" name="wageType" value="2" /> 现金
	                                </label>
	                            </div>
	                            
	                        </div>
	                    </div>
	                    <div class="form-group">
	                    	<label for="collectDate" class="col-sm-3 control-label">住院日期</label>
	                    	<div class="col-sm-5">
	               			    <div class="input-group date form_date" data-date-format="yyyy-mm-dd" data-link-field="inHospitalDate" >
				                    <input class="form-control" type="text" name="inHospitalDate" readonly>
									<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
				                </div>
			                </div>
	                    </div>
	                    <div class="form-group">
	                    	<label for="collectDate" class="col-sm-3 control-label">出院日期</label>
	                    	<div class="col-sm-5">
	               			    <div class="input-group date form_date" data-date-format="yyyy-mm-dd" data-link-field="leaveHospitalDate" >
				                    <input class="form-control" type="text" name="leaveHospitalDate" readonly>
									<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
				                </div>
			                </div>
	                    </div>

	                    <div class="form-group">
	                        <div class="col-sm-9 col-sm-offset-3">
	                            <button type="submit" class="btn btn-primary" id="submitBtn" value="Sign up" >提交</button>
	                        </div>
	                    </div>
	                </form>
	            </div>
	        </div>
	    </div>
	<script type="text/javascript" src="${APP_PATH}/static/jquery/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" src="${APP_PATH}/static/bootstrap-3.3.7/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="${APP_PATH}/static/bootstrap-3.3.7/plugins/fromvalidation/dist/js/formValidation.js"></script>
    <script type="text/javascript" src="${APP_PATH}/static/bootstrap-3.3.7/plugins/fromvalidation/dist/js/framework/bootstrap.js"></script>
    <script type="text/javascript" src="${APP_PATH}/static/bootstrap-3.3.7/plugins/fromvalidation/zh_CN.js"></script>
    <script type="text/javascript" src="${APP_PATH}/static/bootstrap-3.3.7/plugins/datetimepicker/bootstrap-datetimepicker.js"></script>
    <script type="text/javascript" src="${APP_PATH}/static/bootstrap-3.3.7/plugins/datetimepicker/bootstrap-datetimepicker.zh-CN.js"></script>
    <script type="text/javascript">
   
    $(document).ready(function() {
    	
    	$.ajax({
			url:"${APP_PATH}/dict/getdicts",
			data:null,
			type:"GET",
			success:function(result){
				build_hospital(result);
				build_accidentType(result);

			}
		});
    	function build_hospital(result){
			//清空table表格
			$("#hospital").empty();
			var empSelect = $("<option></option>").append("");
			$("#hospital").append(empSelect);
			var dicts = result.extend.dicts;
			$.each(dicts,function(index,item){
				if(item.parentId=='262833e2a9ae4300bb3323e1aa46fb9e'){
					$("#hospital").append($("<option></option>").append(item.name).attr("value",item.value));
				}
			});
		}
    	function build_accidentType(result){
			//清空table表格
			$("#accidentTypeDiv").empty();
			var dicts = result.extend.dicts;
			$.each(dicts,function(index,item){
				if(item.parentId=='ec3b681032ae4333b63abbc1f92cd03a'){
					var inputTmp="<input type='checkbox' name='accidentType' value='"+item.value+"' /> "+item.name;
					var labelTmp=$("<label></label>").append(inputTmp);
					var divTmp =$("<div></div>").append(labelTmp).addClass("checkbox");
					$("#accidentTypeDiv").append(divTmp);
				}
			});
		}
    	$('.form_date').datetimepicker({
            language:  'zh-CN',
            weekStart: 1,
            todayBtn:  1,
    		autoclose: 1,
    		todayHighlight: 1,
    		startView: 2,
    		minView: 2,
    		forceParse: 0
        });
	    
    	
        //$('#defaultForm').formValidation();
       

	    $('#defaultForm').formValidation({
	        message: 'This value is not valid',
	        icon: {
	            valid: 'glyphicon glyphicon-ok',
	            invalid: 'glyphicon glyphicon-remove',
	            validating: 'glyphicon glyphicon-refresh'
	        },
	        fields: {
	        	customerName: {
	                validators: {
	                    notEmpty: {
	                        message: '姓名不能为空'
	                    }
	                }
	            },
	            gender: {
	                validators: {
	                    notEmpty: {
	                        message: '必须选择一个性别'
	                    }
	                }
	            },
	            phone: {
	                validators: {
	                    notEmpty: {
	                        message: '电话号码不能为空'
	                    }
	                }
	            },
	            hospital: {
	                validators: {
	                    notEmpty: {
	                        message: '治疗医院不能为空'
	                    }
	                }
	            },
	            accidentType: {
	            	validators: {
	                    choice: {
	                        min: 1,
	                        max: 2,
	                        message: 'Please choose %s - %s editors you know'
	                    }
	                }
	            },
	            hasContract: {
	                validators: {
	                    notEmpty: {
	                        message: '必须选择是否有劳动合同'
	                    }
	                }
	            },
	            hasInsurance: {
	                validators: {
	                    notEmpty: {
	                        message: '必须选择是否有社保'
	                    }
	                }
	            },
	            wageType:{
	                validators: {
	                    notEmpty: {
	                        message: '必须选择工资结算方式'
	                    }
	                }
	            }
	        }
	    }).on('success.form.fv', function(e) {
            // Prevent form submission
            e.preventDefault();

            // Get the form instance
            var $form = $(e.target);

            // Get the FormValidation instance
            var bv = $form.data('formValidation');

            // Use Ajax to submit form data
            $.post($form.attr('action'), $form.serialize(), function(result) {
            	alert(result.code)
				if(result.code == 200){
					self.location='caselist.jsp';
				}
            }, 'json');
        }); 
	});
    
  //点击新增按钮弹出模态框。
	
	</script>
</body>
</html>